<template>
  <div class="">
    <my-row :rows="tableData" @row-click="rowClick" />
    <row-detail :content="rowNow" :headData="tableHead" />
  </div>
</template>

<script type="text/ecmascript-6">
/*eslint-disable*/
import { getTableHeader,
 findByEnterId,
 getCanBackHistoryNodes,
 findByFormGuid } from '@/api/detail/index.js'
 import MyRow from './child/myrow/index.vue'
 import RowDetail from './child/rowdetail/index'
export default {
  data() {
    return {
      tableHead:[],
      tableData:[],
      rowNow:{},
      isShowDetail:false
    }
  },
  props:{
    collectData:{
      type:Object,
      default(){
        return {}
      }
    }
  },
  methods: {
    rowClick(row){
      this.rowNow = row
      this.isShowDetail = false
      console.log(row);
    },
    isRequestErr(res){
      if (res.code === 200 && res.success) {
        return res.data
      }else{
        // this.$message.warning(res.message)
        return null
      }
    },
    async getTableData(data){
      return await findByFormGuid(data)
    },
    async getTableHeader(data){
        return await getTableHeader(data)
      },
    async pageInit(){
        const { getTableHeader, collectData} = this
        const {  formGuid, title } = collectData
        let tableId = "17"
        if (title) {
          if (title.search('2021')) {
          tableId = "23"
        }
        }

        const tableHeadRequest = await getTableHeader({tableId,title})
        //todo 表头
        const tableHead = this.isRequestErr(tableHeadRequest)
        console.log(tableHead);
        //todo 表体
        const tableDataRequest = await this.getTableData({formGuid,title})
        const tableData = this.isRequestErr(tableDataRequest)
        console.log(tableData);
        if (tableHead && tableData) {
          this.tableData = tableData
          this.tableHead = tableHead
        }
      }
  },
  mounted() {
    this.pageInit()
  },
  components:{
    MyRow,
    RowDetail
  }
}
</script>

<style lang="less" scoped></style>
